<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">

            <p-form layout="inline" @keyup.enter.native="searchQuery">
              <p-row :gutter="24">
                <!-- 条码扫描  -->
                <p-col :xl="6" :lg="7" :md="8" :sm="24">
                  <p-form-item label="条码扫描">
                    <p-input placeholder="" style="width: 200px" />
                  </p-form-item>
                </p-col>
                <!-- 二级工序下拉输入框 -->
                <p-col :xl="6" :lg="7" :md="8" :sm="24">
                    <p-form-item label="二级工序">
                      <j-dict-select-tag placeholder="请选择" v-model="queryParam.filedType" dictCode="mes_filed_type"/>
                    </p-form-item>
                </p-col>
                 <!-- 线体下拉输入框 -->
                  <p-col :xl="6" :lg="7" :md="8" :sm="24">
                    <p-form-item label="线体">
                      <j-dict-select-tag placeholder="请选择" v-model="queryParam.filedType" dictCode="mes_filed_type"/>
                    </p-form-item>
                </p-col>
                 <!-- 工站下拉输入框 -->
                <p-col :xl="6" :lg="7" :md="8" :sm="24">
                    <p-form-item label="工站">
                      <j-dict-select-tag placeholder="请选择" v-model="queryParam.filedType" dictCode="mes_filed_type"/>
                    </p-form-item>
                </p-col>
              </p-row>
            </p-form>

            <!-- 按钮区域 -->
            <div>
              <!-- 产品测试按钮 -->
              <p-button class="BtMargin" @click="handleAdd" type="primary">产品测试</p-button>
              <!-- 超领物料 -->
              <p-button class="BtMargin" @click="handleAdd" type="primary">超领物料</p-button>
              <!-- 生产退料 -->
              <p-button class="BtMargin" @click="handleAdd" type="primary">生产退料</p-button>
              <span class="print">是否在线打印<p-switch class="switch" checked-children="开" un-checked-children="关" default-checked /></span>
            </div>
    </div>

     <!-- Table图表区域 -->
          <div class="container">
                 <!-- 输入框区域 -->
                <div class="inputArea">
                      <!-- 工序工单输入框 -->
                      <div>
                          <label for="">工序工单：</label>
                          <p-input placeholder="请输入" class="inputInfo"/>
                      </div>
                      <!-- 产品编码输入框 -->
                      <div>
                          <label for="">码品编码:</label>
                          <p-input placeholder="请输入" class="inputInfo"/>
                      </div>
                      <!-- 产品名称输入框 -->
                      <div>
                          <label for="">产品名称：</label>
                          <p-input placeholder="请输入" class="inputInfo"/>
                      </div>
                      <!-- 计划数量输入框 -->
                      <div>
                          <label for="">计划数量：</label>
                          <p-input placeholder="1000" class="inputInfo"/>
                      </div>
                 </div>

      <div class="right">
          <div class="rightContainer_top">
              <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
                <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
                <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
          </div>
          <div class="rightContainer_bottom">
                 <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
                <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
               <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
          </div>
          <div class="rightContainer_bottom">
                <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
                 <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
                <div class="container_1">
                    <div class="container1_2">
                        <div class="container1_2_1">电动点检</div>
                        <div class="container1_2_2"><p-tag color="blue">待点检</p-tag></div>
                      </div> 
                      <div class="container1_2_3">点检单号：HX-DJ200524001</div>
              </div>  
          </div>
             <div class="setPage">
                  <p-pagination v-model="ipagination.current" :total="50" show-less-items />
            </div>
    </div>
                 </div>
                
              </div>
      </p-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {api} from '@/api/manage'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import { filterObj } from '@/utils/util'
  import MesMfOpenLineInspectionListModal from './modules/MesMfOpenLineInspectionListModal'
  import Vue from 'vue'
  import MesMfLineTheTallyList from './MesMfLineTheTallyList'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
  import { postAction,getAction,deleteAction } from '@/api/manage'
  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"

  //高级查询modal需要参数
    const superQueryFieldList=[
            {
                value:'workclassno',
                text: '班组编码',
                type: 'string'
            },
            {
                value:'workclassname',
                text: '班组名称',
                type: 'string'
            },
            {
                value:'lineno',
                text: '线体编码',
                type: 'string'
            },
            {
                value:'linename',
                text: '线体名称',
                type: 'string'
            },
            {
                value:'workroomno',
                text: '车间编码',
                type: 'string'
            },
            {
                value:'workroomname',
                text: '车间名称',
                type: 'string'
            },
            {
                value:'mnum',
                text: '计划数量',
                type: 'string'
            },
            {
                value:'mobillno',
                text: '工序工单编号',
                type: 'string'
            },
            {
                value:'spotcheckTemplate',
                text: '检验模板',
                type: 'select',
                dictCode: 'mes_spotcheck_template'
            },
            {
                value:'istates',
                text: '检验状态',
                type: 'string'
            },
            {
                value:'decide',
                text: '检验判定',
                type: 'select',
                dictCode: 'mes_is_qualified'
            },
            {
                value:'personnel',
                text: '点检人员',
                type: 'string'
            },
            {
                value:'theTallyTime',
                text: '点检时间',
                type: 'string'
            },
            {
                value:'createBy',
                text: '创建人',
                type: 'string'
            },
            {
                value:'createTime',
                text: '创建日期',
                type: 'Date'
            },
            {
                value:'updateBy',
                text: '更新人',
                type: 'string'
            },
            {
                value:'updateTime',
                text: '更新日期',
                type: 'Date'
            },
    ]

  export default {
    name: "MesMfOpenLineInspectionListList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      JDictSelectTag,
      MesMfLineTheTallyList,
      FxCompontensModal,
      MesMfOpenLineInspectionListModal
    },
    data () {
      return {
        fieldList:superQueryFieldList,
        superQueryFlag:false,
        superQueryParams: '',
        description: '开线点检单管理页面',
        EnhanceJS:'',
        cgButtonLinkList:[],
        cgButtonList:[],
        title:'',//存表名
        groupTag:[],
        queryInfo: [],
        code: '',
        // 表头
        columns: [],
         //列设置
         settingColumns:[],
         //列定义
         defColumns: [
          {
            title: '班组编码',
            align: 'center',
            dataIndex: 'workclassno',
          },
          {
            title: '班组名称',
            align: 'center',
            dataIndex: 'workclassname',
          },
          {
            title: '线体编码',
            align: 'center',
            dataIndex: 'lineno',
          },
          {
            title: '线体名称',
            align: 'center',
            dataIndex: 'linename',
          },
          {
            title: '车间编码',
            align: 'center',
            dataIndex: 'workroomno',
          },
          {
            title: '车间名称',
            align: 'center',
            dataIndex: 'workroomname',
          },
          {
            title: '计划数量',
            align: 'center',
            dataIndex: 'mnum',
          },
          {
            title: '工序工单编号',
            align: 'center',
            dataIndex: 'mobillno',
          },
          {
            title: '检验模板',
            align: 'center',
            dataIndex: 'spotcheckTemplate',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['spotcheckTemplate'], text+"")
              }
            },
          },
          {
            title: '检验状态',
            align: 'center',
            dataIndex: 'istates',
          },
          {
            title: '检验判定',
            align: 'center',
            dataIndex: 'decide',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['decide'], text+"")
              }
            },
          },
          {
            title: '点检人员',
            align: 'center',
            dataIndex: 'personnel',
          },
          {
            title: '点检时间',
            align: 'center',
            dataIndex: 'theTallyTime',
          },
          {
            title: '创建人',
            align: 'center',
            dataIndex: 'createBy',
          },
          {
            title: '创建日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            },
          },
          {
            title: '更新人',
            align: 'center',
            dataIndex: 'updateBy',
          },
          {
            title: '更新日期',
            align: 'center',
            dataIndex: 'updateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: '/mes-manufacture/auto/mesMfOpenLineInspectionList/list',
          delete: '/mes-manufacture/auto/mesMfOpenLineInspectionList/delete',
          deleteBatch: '/mes-manufacture/auto/mesMfOpenLineInspectionList/deleteBatch',
          exportXlsUrl: '/mes-manufacture/auto/mesMfOpenLineInspectionList/exportXls',
          importExcelUrl: '/mes-manufacture/auto/mesMfOpenLineInspectionList/importExcel',
          getColumns: '/mes-manufacture/online/cgform/api/getColumns/',
          buttonAction: '/mes-manufacture/online/cgform/api/doButton',
        },
        dictOptions:{
         spotcheckTemplate:[],
         decide:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:''

      }
    },
    computed: {
      importExcelUrl: function(){
        return `${api.test}${this.url.importExcelUrl}`;
      },
      getWidth:function(){
        if(this.defColumns.length > 14){
          return {width : '500px'}
        }
      },
      newSelectedMainId:function(){
        if(typeof(this.selectedMainId) == 'number'){
          return this.selectedMainId.toString()
        }else{
          return this.selectedMainId
        }
      },
			tableScroll:function(){
			 if(this.columns.length > 13){
					return { x: this.columns.length*150-450 }
				}
			}
    },

     created() {
          this.initButtonList();
          this.initColumns();
          this.setdefColumns();
     },


    methods: {

      setdefColumns(){
        if(this.columns.length > 13){
          let arrLength = this.columns.length-1
          this.columns.forEach((item,index)=>{
            item["width"] = 130
          })
          this.columns[arrLength]['fixed'] = 'right'
          this.columns[0]['fixed'] = 'left'
          this.columns[1]['fixed'] = 'left'
        }
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },
        //高级查询方法
        handleSuperQuery(arg) {
            if(!arg){
                this.superQueryParams=''
                this.superQueryFlag = false
            }else{
                this.superQueryFlag = true
                this.superQueryParams=JSON.stringify(arg)
            }
            this.loadData()
        },
        // 获取查询条件
        getQueryParams() {
            let sqp = {}
            if(this.superQueryParams){
                sqp['superQueryParams']=encodeURI(this.superQueryParams)
            }
            var param = Object.assign(sqp, this.queryParam, this.isorter);
            param.field = this.getQueryField();
            param.pageNo = this.ipagination.current;
            param.limit = this.ipagination.pageSize;
            return filterObj(param);
        },
      initDictConfig(){
        initDictOptions('mes_spotcheck_template').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'spotcheckTemplate', res.data)
          }
        })
        initDictOptions('mes_is_qualified').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'decide', res.data)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.data.records;
            this.ipagination.total = res.data.total;
          }
          if(res.code===510){
            this.$message.warning(res.msg)
          }
          this.loading = false;
        })
      },

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName,title){
        getAction(`${this.url.getColumns}`,{
          tableName:tableName
        }).then(
          res=>{
            if(res.code == 0){
              this.queryInfo = res.data.columns
              this.title = title
              this.dictOptions = res.data.dictOptions
              this.showDemoModal()
            }else{
               this.$message.warning(res.msg);
            }
          }
        )
      },

      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
            dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai]
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest
        console.log(dest);
      },
      showLinkButton(item,record){
          let btn = new ButtonExpHandler(item.exp,record);
          return btn.show;
      },
        initButtonList(){
          getAction(`${this.url.getColumns}8ac49ec7733bce48017355896388012b`).then((res)=>{
            console.log("--获取自定义按钮->>",res);
            if(res.success){
              this.code = res.data.code;
              this.initCgButtonList(res.data.cgButtonList);
              this.initCgEnhanceJs(res.data.enhanceJs);
              this.getGroupTag(res.data.cgButtonList);
            }else{
              this.$message.warning(res.msg)
            }
          })
        },
        initCgEnhanceJs(enhanceJs){
          //console.log("--onlineList-js增强",enhanceJs)
          if(enhanceJs){
            let Obj = eval ("(" + enhanceJs + ")");
            this.EnhanceJS = new Obj(getAction,postAction,deleteAction);
            this.cgButtonJsHandler('created')
          }else{
            this.EnhanceJS = ''
          }
        },
        initCgButtonList(btnList){
          let linkArr = []
          let buttonArr = []
          if(btnList && btnList.length>0){
            for(let i=0;i<btnList.length;i++){
              let temp = btnList[i]
              if(temp.buttonStyle=='button'){
                buttonArr.push(temp)
              }else if(temp.buttonStyle=='link'){
                linkArr.push(temp)
              }
            }
          }
          this.cgButtonLinkList = [...linkArr]
          this.cgButtonList=[...buttonArr]
          console.log("链接增强", this.cgButtonLinkList);
        },
        cgButtonJsHandler(buttonCode){
          if(this.EnhanceJS[buttonCode]){
            this.EnhanceJS[buttonCode](this)
          }
        },
        cgButtonActionHandler(buttonCode){
          //处理自定义button的 需要配置该button自定义sql
          if(!this.selectedRowKeys || this.selectedRowKeys.length==0){
            this.$message.warning("请先选中一条记录")
            return false
          }
          if(this.selectedRowKeys.length>1){
            this.$message.warning("请只选中一条记录")
            return false
          }
          let params = {
            formId:this.code,
            buttonCode:buttonCode,
            dataId:this.selectedRowKeys[0]
          }
          console.log("自定义按钮请求后台参数：",params)
          postAction(this.url.buttonAction,params).then(res=>{
            if(res.success){
              this.loadData()
              this.$message.success("处理完成!")
            }else{
              this.$message.warning("处理失败!")
            }
          })

        },
        cgButtonLinkHandler(record,buttonCode,optType){
          if(optType=="js"){
            if(this.EnhanceJS[buttonCode]){
              this.EnhanceJS[buttonCode](this,record)
            }
          }else if(optType=="action"){
            let params = {
              formId:this.code,
              buttonCode:buttonCode,
              dataId:record.id
            }
            console.log("自定义按钮link请求后台参数：",params)
            postAction(this.url.buttonAction,params).then(res=>{
              if(res.success){
                this.loadData()
                this.$message.success("处理完成!")
              }else{
                this.$message.warning("处理失败!")
              }
            })
          }
        },

    }
  }
</script>
<style scoped>
 @import '~@assets/less/common.less';

  .BtMargin{
    margin-right:10px;
  }
  .sprint i{  
    margin-left: 20px;
  }

  .switch{
      margin-left:10px;
  }
 
.ant-empty-normal{
  margin:0
}
.container{
  height:700px;
  display:flex;
  margin-top:20px;
  flex-direction:column;
  border:1px solid #eee;
}
.inputArea{
  display: flex;
  justify-content: space-evenly;
  margin:20px 0;
}
.inputInfo{
  width:150px;
}
.right{
  flex-grow:1;
  /* border:1px solid #eee; */
}
.rightContainer_top,
.rightContainer_bottom{
  display:flex;
  justify-content:space-around;
  margin-top:50px;
}
.container_1,
.container_2,
.container_3{
  border:1px solid #eee;
  height:100%;
  width:300px;
  flex-direction:column;
}

.container1_2{
  display:flex;
}
.container1_2_1,
.container1_2_2{
  flex-grow:1;
  height:50px;
  line-height:50px;
  padding-left:10px;
}
.container1_2_2{
  padding-left:150px;
}
.container1_2_3{
   margin:10px auto;
   padding:10px;
}
.setPage{
  display:flex;
  justify-content:center;
  margin-top:50px;
}


</style>
